package com.chess.config;

import java.util.Date;

import com.chess.constant.AppConstant;
import com.chess.job.TokenJob;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.json.FastJsonFactory;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.template.Engine;
import com.sojoys.artifact.core.IServer;
import com.sojoys.artifact.manager.ContextManager;
import com.sojoys.artifact.manager.PropManager;
import com.sojoys.artifact.plugin.quartz.QuartzPlugin;

/**
 * @author : DengYing
 * @CreateDate : 2017年4月10日 下午5:00:59
 * @Description ：Please describe this document
 */
public class ChessConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants constants) {
		PropKit.use("app.properties");
		PropManager.use("app.properties");
		ContextManager.init("app-init.xml");
		
		constants.setEncoding("UTF-8");
		
		constants.setDevMode(PropKit.getBoolean(AppConstant.config_devMode, false));
		
		constants.setBaseUploadPath(PathKit.getWebRootPath()); // 上传公共路径 + File.separator + "files"
		
		constants.setBaseDownloadPath(PathKit.getWebRootPath()); // 下载公共路径 + File.separator + "files"
		// 设置默认JSON工厂
		constants.setJsonFactory(FastJsonFactory.me());
	}

	@Override
	public void configRoute(Routes routes) {
		routes.add(new RoutesScan());
	}

	@Override
	public void configEngine(Engine me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterJFinalStart() {
		IServer.setIConfig(new NettyConfig());
		IServer.start();
		
		//30秒检查一直过期token
		QuartzPlugin.addJob("token", "token", new Date(), "* * * * * ? *", TokenJob.class, null);
	}

	@Override
	public void beforeJFinalStop() {
		IServer.stop();
	}

	
}
